use std::cell::RefCell;
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
use rjvm_class_path::class_file_packet::ClassFilePacket;
use rjvm_class_path::composite_class_file_packet::CompositeClassFilePacket;
use rjvm_class_path::dir_class_file_packet::DirClassFilePacket;
use rjvm_class_path::jar_class_file_packet::JarClassFilePacket;
use rjvm_class_path::jmod_class_file_packet::JmodClassFilePacket;

#[test]
fn jmod_class_file_packet_test() {
    let jmod_class_file_packet = JmodClassFilePacket { jmod_file_path: RefCell::new("C://Software//jdk-11.0.11+9//jmods//java.base.jmod".to_string()) };

    let result = jmod_class_file_packet.read_class(&"java/lang/Object".to_string());
    match result {
        Ok(data) => {
            println!("success");
        }
        Err(message) => {
            println!("{}", message);
        }
    }
}

#[test]
fn jar_class_file_packet_test() {
    let jar_class_file_packet = JarClassFilePacket { jar_file_path: RefCell::new("C:/Code/qinghotel-app/qinghotel-app-api/target/qinghotel-app-api-1.4.0-SNAPSHOT.jar".to_string()) };

    let result = jar_class_file_packet.read_class(&"com/qinghotel/app/constants/FeignClientName".to_string());
    match result {
        Ok(data) => {
            println!("success");
        }
        Err(message) => {
            println!("{}", message);
        }
    }
}


#[test]
fn dir_class_file_packet_test() {
    let dir_class_file_packet = DirClassFilePacket { dir_path: RefCell::new("C://Code//qinghotel-app//qinghotel-app-server//target//classes/".to_string()) };

    let result = dir_class_file_packet.read_class(&"com/qinghotel/app/QinghotelAppConfig".to_string());
    match result {
        Ok(data) => {
            println!("success");
        }
        Err(message) => {
            println!("{}", message);
        }
    }
}

fn create_composite_class_file_packet() -> CompositeClassFilePacket {
    // pub class_file_packet_list: &'a mut Vec<&'a dyn ClassFilePacket>,
    // let mut b: Box<&mut Vec<&dyn ClassFilePacket>> = Box::new(&mut Vec::new());
    // let l = b.leak();
    // let v = b.leak().to_vec();

    // let r:Rc<Vec<&dyn ClassFilePacket>> = Rc::new(Vec::new());

    CompositeClassFilePacket {
        class_file_packet_list: RefCell::new(Vec::new())
    }
}

#[test]
fn composite_class_file_packet_test() {
    let class_file_packet = create_composite_class_file_packet();
    let dir_class_file_packet = DirClassFilePacket {
        dir_path: RefCell::new("C://Code//qinghotel-app//qinghotel-app-server//target//classes/".to_string())
    };
    let jar_class_file_packet = JarClassFilePacket {
        jar_file_path: RefCell::new("C:/Code/qinghotel-app/qinghotel-app-api/target/qinghotel-app-api-1.4.0-SNAPSHOT.jar".to_string())
    };
    let jmod_class_file_packet = JmodClassFilePacket {
        jmod_file_path: RefCell::new("C://Software//jdk-11.0.11+9//jmods//java.base.jmod".to_string())
    };

    class_file_packet.class_file_packet_list.borrow_mut().push(Box::new(dir_class_file_packet));
    class_file_packet.class_file_packet_list.borrow_mut().push(Box::new(jar_class_file_packet));
    class_file_packet.class_file_packet_list.borrow_mut().push(Box::new(jmod_class_file_packet));

    let result = class_file_packet.read_class(&"com/qinghotel/app/QinghotelAppConfig".to_string());
    match result {
        Ok(_data) => {
            println!("success");
        }
        Err(message) => {
            println!("{}", message);
        }
    }
}